EMMA Coverage Report (generated Sat Sep 03 18:56:48 CEST 2016)
[all classes][kdk.android.simplydo]

COVERAGE SUMMARY FOR SOURCE FILE [SimplyDoActivity.java]

nameclass, %method, %block, %line, %
SimplyDoActivity.java100% (15/15)94%  (65/69)92%  (1368/1495)89%  (313,9/351)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SimplyDoActivity$7100% (1/1)50%  (1/2)27%  (6/22)25%  (1/4)
onEditorAction (TextView, int, KeyEvent): boolean 0%   (0/1)0%   (0/16)0%   (0/3)
SimplyDoActivity$7 (SimplyDoActivity): void 100% (1/1)100% (6/6)100% (1/1)
     
class SimplyDoActivity$12100% (1/1)50%  (1/2)29%  (6/21)17%  (1/6)
onEditorAction (TextView, int, KeyEvent): boolean 0%   (0/1)0%   (0/15)0%   (0/5)
SimplyDoActivity$12 (SimplyDoActivity): void 100% (1/1)100% (6/6)100% (1/1)
     
class SimplyDoActivity$8100% (1/1)50%  (1/2)55%  (6/11)33%  (1/3)
onEditorAction (TextView, int, KeyEvent): boolean 0%   (0/1)0%   (0/5)0%   (0/2)
SimplyDoActivity$8 (SimplyDoActivity): void 100% (1/1)100% (6/6)100% (1/1)
     
class SimplyDoActivity$10100% (1/1)100% (2/2)90%  (19/21)83%  (5/6)
onEditorAction (TextView, int, KeyEvent): boolean 100% (1/1)87%  (13/15)80%  (4/5)
SimplyDoActivity$10 (SimplyDoActivity): void 100% (1/1)100% (6/6)100% (1/1)
     
class SimplyDoActivity100% (1/1)97%  (36/37)92%  (1075/1164)91%  (257,9/284)
access$900 (SimplyDoActivity): AlertDialog 0%   (0/1)0%   (0/3)0%   (0/1)
onPrepareDialog (int, Dialog): void 100% (1/1)75%  (45/60)65%  (11/17)
listSelected (ListDesc, boolean): void 100% (1/1)78%  (28/36)73%  (8/11)
onMenuItemSelected (int, MenuItem): boolean 100% (1/1)84%  (128/153)82%  (36/44)
addItem (): void 100% (1/1)90%  (36/40)92%  (11/12)
onCreate (Bundle): void 100% (1/1)92%  (327/355)91%  (68/75)
itemSelected (ItemDesc): void 100% (1/1)94%  (31/33)99%  (5,9/6)
onCreateDialog (int): Dialog 100% (1/1)94%  (63/67)95%  (21/22)
<static initializer> 100% (1/1)100% (3/3)100% (1/1)
SimplyDoActivity (): void 100% (1/1)100% (27/27)100% (5/5)
access$1000 (SimplyDoActivity): ItemDesc 100% (1/1)100% (3/3)100% (1/1)
access$1002 (SimplyDoActivity, ItemDesc): ItemDesc 100% (1/1)100% (5/5)100% (1/1)
access$1100 (SimplyDoActivity): DataViewer 100% (1/1)100% (3/3)100% (1/1)
access$1200 (SimplyDoActivity, ItemDesc): void 100% (1/1)100% (4/4)100% (1/1)
access$1300 (SimplyDoActivity, ListDesc, boolean): void 100% (1/1)100% (5/5)100% (1/1)
access$1402 (SimplyDoActivity, ListDesc): ListDesc 100% (1/1)100% (5/5)100% (1/1)
access$200 (SimplyDoActivity): void 100% (1/1)100% (3/3)100% (1/1)
access$300 (SimplyDoActivity): void 100% (1/1)100% (3/3)100% (1/1)
access$400 (SimplyDoActivity): void 100% (1/1)100% (3/3)100% (1/1)
access$500 (SimplyDoActivity): void 100% (1/1)100% (3/3)100% (1/1)
access$600 (SimplyDoActivity): void 100% (1/1)100% (3/3)100% (1/1)
access$700 (SimplyDoActivity): AlertDialog 100% (1/1)100% (3/3)100% (1/1)
access$800 (SimplyDoActivity): void 100% (1/1)100% (3/3)100% (1/1)
addList (): void 100% (1/1)100% (32/32)100% (9/9)
cacheInvalidated (): void 100% (1/1)100% (27/27)100% (9/9)
contextDeleteItem (): void 100% (1/1)100% (28/28)100% (6/6)
contextDeleteList (): void 100% (1/1)100% (26/26)100% (5/5)
getDataVeiwer (): DataViewer 100% (1/1)100% (3/3)100% (1/1)
getInstance (): SimplyDoActivity 100% (1/1)100% (2/2)100% (1/1)
itemEditOk (): void 100% (1/1)100% (24/24)100% (6/6)
listEditOk (): void 100% (1/1)100% (20/20)100% (5/5)
onBackPressed (): void 100% (1/1)100% (30/30)100% (10/10)
onCreateOptionsMenu (Menu): boolean 100% (1/1)100% (8/8)100% (2/2)
onDestroy (): void 100% (1/1)100% (12/12)100% (5/5)
onPrepareOptionsMenu (Menu): boolean 100% (1/1)100% (57/57)100% (13/13)
onSaveInstanceState (Bundle): void 100% (1/1)100% (25/25)100% (7/7)
onStart (): void 100% (1/1)100% (47/47)100% (12/12)
     
class SimplyDoActivity$1100% (1/1)100% (2/2)100% (10/10)100% (3/3)
SimplyDoActivity$1 (SimplyDoActivity): void 100% (1/1)100% (6/6)100% (1/1)
onClick (View): void 100% (1/1)100% (4/4)100% (2/2)
     
class SimplyDoActivity$11100% (1/1)100% (2/2)100% (10/10)100% (3/3)
SimplyDoActivity$11 (SimplyDoActivity): void 100% (1/1)100% (6/6)100% (1/1)
onClick (DialogInterface, int): void 100% (1/1)100% (4/4)100% (2/2)
     
class SimplyDoActivity$2100% (1/1)100% (2/2)100% (10/10)100% (3/3)
SimplyDoActivity$2 (SimplyDoActivity): void 100% (1/1)100% (6/6)100% (1/1)
onClick (View): void 100% (1/1)100% (4/4)100% (2/2)
     
class SimplyDoActivity$3100% (1/1)100% (2/2)100% (9/9)100% (3/3)
SimplyDoActivity$3 (SimplyDoActivity): void 100% (1/1)100% (6/6)100% (1/1)
onClick (DialogInterface, int): void 100% (1/1)100% (3/3)100% (2/2)
     
class SimplyDoActivity$4100% (1/1)100% (2/2)100% (12/12)100% (4/4)
SimplyDoActivity$4 (SimplyDoActivity): void 100% (1/1)100% (6/6)100% (1/1)
onClick (DialogInterface, int): void 100% (1/1)100% (6/6)100% (3/3)
     
class SimplyDoActivity$5100% (1/1)100% (2/2)100% (9/9)100% (3/3)
SimplyDoActivity$5 (SimplyDoActivity): void 100% (1/1)100% (6/6)100% (1/1)
onClick (DialogInterface, int): void 100% (1/1)100% (3/3)100% (2/2)
     
class SimplyDoActivity$6100% (1/1)100% (2/2)100% (12/12)100% (4/4)
SimplyDoActivity$6 (SimplyDoActivity): void 100% (1/1)100% (6/6)100% (1/1)
onClick (DialogInterface, int): void 100% (1/1)100% (6/6)100% (3/3)
     
class SimplyDoActivity$9100% (1/1)100% (2/2)100% (10/10)100% (3/3)
SimplyDoActivity$9 (SimplyDoActivity): void 100% (1/1)100% (6/6)100% (1/1)
onClick (DialogInterface, int): void 100% (1/1)100% (4/4)100% (2/2)
     
class SimplyDoActivity$ItemsListReactor100% (1/1)100% (4/4)100% (102/102)100% (20/20)
SimplyDoActivity$ItemsListReactor (SimplyDoActivity): void 100% (1/1)100% (6/6)100% (1/1)
SimplyDoActivity$ItemsListReactor (SimplyDoActivity, SimplyDoActivity$1): void 100% (1/1)100% (4/4)100% (1/1)
onCreateContextMenu (ContextMenu, View, ContextMenu$ContextMenuInfo): void 100% (1/1)100% (72/72)100% (14/14)
onItemClick (AdapterView, View, int, long): void 100% (1/1)100% (20/20)100% (5/5)
     
class SimplyDoActivity$ListsListReactor100% (1/1)100% (4/4)100% (72/72)100% (14/14)
SimplyDoActivity$ListsListReactor (SimplyDoActivity): void 100% (1/1)100% (6/6)100% (1/1)
SimplyDoActivity$ListsListReactor (SimplyDoActivity, SimplyDoActivity$1): void 100% (1/1)100% (4/4)100% (1/1)
onCreateContextMenu (ContextMenu, View, ContextMenu$ContextMenuInfo): void 100% (1/1)100% (41/41)100% (8/8)
onItemClick (AdapterView, View, int, long): void 100% (1/1)100% (21/21)100% (5/5)

1/*
2 * Copyright (C) 2013, 2011 Keith Kildare
3 * 
4 * This file is part of SimplyDo.
5 * 
6 * SimplyDo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 * 
11 * SimplyDo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 * 
16 * You should have received a copy of the GNU General Public License
17 * along with SimplyDo.  If not, see <http://www.gnu.org/licenses/>.
18 * 
19 */
20package kdk.android.simplydo;
21 
22import android.app.Activity;
23import android.app.AlertDialog;
24import android.app.Dialog;
25import android.content.DialogInterface;
26import android.content.Intent;
27import android.content.SharedPreferences;
28import android.os.Bundle;
29import android.preference.PreferenceManager;
30import android.util.Log;
31import android.view.ContextMenu;
32import android.view.KeyEvent;
33import android.view.LayoutInflater;
34import android.view.Menu;
35import android.view.MenuItem;
36import android.view.View;
37import android.view.ViewGroup;
38import android.view.WindowManager;
39import android.view.ContextMenu.ContextMenuInfo;
40import android.view.animation.AnimationUtils;
41import android.widget.AdapterView;
42import android.widget.Button;
43import android.widget.EditText;
44import android.widget.ListView;
45import android.widget.TextView;
46import android.widget.ViewSwitcher;
47import android.widget.AdapterView.AdapterContextMenuInfo;
48import android.widget.AdapterView.OnItemClickListener;
49import android.widget.TextView.OnEditorActionListener;
50 
51public class SimplyDoActivity extends Activity 
52{
53    private static final int DELETE_INACTIVE = 100;
54    private static final int DELETE_LIST     = 101;
55    private static final int EDIT_LIST       = 102;
56    private static final int DELETE_ITEM     = 103;
57    private static final int EDIT_ITEM       = 104;
58    private static final int TOGGLE_STAR     = 105;
59    private static final int SETTINGS        = 106;
60    private static final int SORT_NOW        = 107;
61    private static final int MOVE_ITEM       = 108;
62    
63    private static final int DIALOG_LIST_DELETE = 200;
64    private static final int DIALOG_ITEM_DELETE = 201;
65    private static final int DIALOG_LIST_EDIT = 202;
66    private static final int DIALOG_ITEM_EDIT = 203;
67    private static final int DIALOG_ITEM_MOVE = 204;
68    private static final int DIALOG_DELETE_INACTIVE = 205;
69    
70    private static SimplyDoActivity instance = null;
71    
72    private DataViewer dataViewer;
73    private ListPropertiesAdapter listPropertiesAdapter;
74    private ItemPropertiesAdapter itemPropertiesAdapter;
75    
76    private ListsListReactor listsListReactor = new ListsListReactor();
77    private ItemsListReactor itemsListReactor = new ItemsListReactor();
78    
79    private ItemDesc ctxItem;
80    private ListDesc ctxList;
81    
82    private AlertDialog.Builder itemDeleteBuilder;
83    private AlertDialog.Builder listDeleteBuilder;
84    
85    private AlertDialog.Builder listEditBuilder;
86    private AlertDialog listEditDialog;
87    
88    private AlertDialog.Builder itemEditBuilder;
89    private AlertDialog itemEditDialog;
90    
91    private EditText itemEditView;
92    private EditText listEditView;
93    
94    private ListListSorter listListSorter = new ListListSorter();
95    private ItemListSorter itemListSorter = new ItemListSorter();
96    
97    private MoveToAction moveItemToAction;
98    private DeleteInactiveAction deleteInactiveAction;
99 
100    
101    /** Called when the activity is first created. */
102    @Override
103    public void onCreate(Bundle savedInstanceState) 
104    {
105        Log.v(L.TAG, "SimplyDoActivity.onCreate() called");
106        
107        super.onCreate(savedInstanceState);
108        
109        setContentView(R.layout.main);
110        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
111                
112        DataManager dataManager = new DataManager(this);
113        
114        CachingDataViewer cdv = new CachingDataViewer(dataManager);
115        cdv.start();
116        dataViewer = cdv;
117        
118        listPropertiesAdapter = new ListPropertiesAdapter(this, dataViewer);
119        
120        ListView listView = (ListView)findViewById(R.id.ListsListView);
121        listView.setAdapter(listPropertiesAdapter);
122        listView.setOnCreateContextMenuListener(listsListReactor);
123        listView.setOnItemClickListener(listsListReactor);
124        
125        itemPropertiesAdapter = new ItemPropertiesAdapter(this, dataViewer);
126        ListView itemView = (ListView)findViewById(R.id.ItemsListView);
127        itemView.setAdapter(itemPropertiesAdapter);
128        itemView.setOnCreateContextMenuListener(itemsListReactor);
129        itemView.setOnItemClickListener(itemsListReactor);
130        
131        Button addList = (Button)findViewById(R.id.AddListButton);
132        addList.setOnClickListener(new View.OnClickListener() {
133            @Override
134            public void onClick(View v)
135            {
136                addList();
137            }
138        });
139        
140        Button addItem = (Button)findViewById(R.id.AddItemButton);
141        addItem.setOnClickListener(new View.OnClickListener() {
142            @Override
143            public void onClick(View v)
144            {
145                addItem();
146            }
147        });
148        
149        ViewSwitcher viewSwitch = (ViewSwitcher)findViewById(R.id.ListsItemsSwitcher);
150        viewSwitch.setInAnimation(AnimationUtils.loadAnimation(this,
151                android.R.anim.slide_in_left));
152        viewSwitch.setOutAnimation(AnimationUtils.loadAnimation(this,
153                android.R.anim.slide_out_right));
154        
155        listDeleteBuilder = new AlertDialog.Builder(this);
156        listDeleteBuilder.setMessage(R.string.listDeleteMessage)
157               .setCancelable(true)
158               .setTitle(R.string.listDeleteTitle)
159               .setPositiveButton(R.string.listDeletePositive, new DialogInterface.OnClickListener() {
160                   public void onClick(DialogInterface dialog, int id) {
161                       contextDeleteList();
162                       dialog.cancel();
163                   }
164               })
165               .setNegativeButton(R.string.listDeleteNegative, new DialogInterface.OnClickListener() {
166                   public void onClick(DialogInterface dialog, int id) {
167                        dialog.cancel();
168                   }
169               });
170        
171        itemDeleteBuilder = new AlertDialog.Builder(this);
172        itemDeleteBuilder.setMessage(
173                R.string.itemDeleteMessage)
174               .setCancelable(true)
175               .setTitle(R.string.itemDeleteTitle)
176               .setPositiveButton(R.string.itemDeletePositive, new DialogInterface.OnClickListener() {
177                   public void onClick(DialogInterface dialog, int id) {
178                       contextDeleteItem();
179                       dialog.cancel();
180                   }
181               })
182               .setNegativeButton(R.string.itemDeleteNegative, new DialogInterface.OnClickListener() {
183                   public void onClick(DialogInterface dialog, int id) {
184                        dialog.cancel();
185                   }
186               });
187        
188        EditText addListEditText = (EditText)findViewById(R.id.AddListEditText);
189        addListEditText.setOnEditorActionListener(new OnEditorActionListener() {
190            @Override
191            public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
192            {
193                Log.d(L.TAG, "Editor Action " + actionId);
194                addList();
195                return true;
196            }
197        });
198        
199        EditText addItemEditText = (EditText)findViewById(R.id.AddItemEditText);
200        addItemEditText.setOnEditorActionListener(new OnEditorActionListener() {
201            @Override
202            public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
203            {
204                addItem();
205                return true;
206            }
207        });
208        
209        LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
210        
211        View itemEditLayout = inflater.inflate(R.layout.item_edit, (ViewGroup)findViewById(R.id.item_edit_root));
212        
213        itemEditBuilder = new AlertDialog.Builder(this);
214        itemEditBuilder.setView(itemEditLayout)
215            .setCancelable(true)
216            .setTitle(R.string.itemEditTitle)
217            .setPositiveButton(R.string.itemEditPositive, new DialogInterface.OnClickListener() {
218                public void onClick(DialogInterface dialog, int id) {
219                    itemEditOk();
220                }
221            })
222            .setNegativeButton(R.string.itemEditNegative, null);
223 
224        itemEditView = (EditText)itemEditLayout.findViewById(R.id.EditItemLabelEditText);
225        itemEditView.setOnEditorActionListener(new OnEditorActionListener() {
226            @Override
227            public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
228            {
229                if(itemEditDialog != null)
230                {
231                    itemEditOk();
232                    itemEditDialog.cancel();
233                    return true;
234                }
235                else
236                {
237                    return false;
238                }
239            }
240        });
241        
242        View listEditLayout = inflater.inflate(R.layout.list_edit, (ViewGroup)findViewById(R.id.list_edit_root));
243 
244        listEditBuilder = new AlertDialog.Builder(this);
245        listEditBuilder.setView(listEditLayout)
246            .setCancelable(true)
247            .setTitle(R.string.listEditTitle)
248            .setPositiveButton(R.string.listEditPositive, new DialogInterface.OnClickListener() {
249                public void onClick(DialogInterface dialog, int id) {
250                    listEditOk();
251                }
252            })
253            .setNegativeButton(R.string.listEditNegative, null);
254                
255        listEditView = (EditText)listEditLayout.findViewById(R.id.EditListLabelEditText);
256        listEditView.setOnEditorActionListener(new OnEditorActionListener() {
257            @Override
258            public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
259            {
260                if(listEditDialog != null)
261                {
262                    listEditOk();
263                    listEditDialog.cancel();
264                    return true;
265                }
266                else
267                {
268                    return false;
269                }
270            }
271        });
272        
273        dataViewer.fetchLists();
274        listPropertiesAdapter.notifyDataSetChanged();
275        
276        moveItemToAction = new MoveToAction(
277                this, 
278                dataViewer, 
279                listPropertiesAdapter, 
280                itemPropertiesAdapter);
281        
282        deleteInactiveAction = new DeleteInactiveAction(
283                this, 
284                dataViewer, 
285                listPropertiesAdapter, 
286                itemPropertiesAdapter);
287        
288        if (savedInstanceState==null) 
289        {
290            Log.d(L.TAG, "SimplyDoActivity.onCreate()");
291        }
292        else 
293        {
294            Log.d(L.TAG, "SimplyDoActivity.onCreate() with a supplied state");
295            
296            Integer listId = (Integer)savedInstanceState.getSerializable("currentListId");
297            if(listId != null)
298            {
299                ListDesc listDesc = dataViewer.fetchList(listId);
300                if(listDesc != null)
301                {
302                    listSelected(listDesc, false);
303                }
304                else
305                {
306                    Log.w(L.TAG, "SimplyDoActivity.onCreate(): savedInstanceState had bad list ID");
307                }
308            }
309        }
310        
311        instance = this;
312    }
313    
314    public static SimplyDoActivity getInstance()
315    {
316        return instance;
317    }
318    
319    public DataViewer getDataVeiwer()
320    {
321        return dataViewer;
322    }
323    
324    public void cacheInvalidated()
325    {
326        Log.v(L.TAG, "SimplyDoActivity.cacheInvalidated(): Entered");
327        
328        ViewSwitcher viewSwitch = (ViewSwitcher)findViewById(R.id.ListsItemsSwitcher);
329        int displayed = viewSwitch.getDisplayedChild();
330        if(displayed == 1)
331        {
332            setTitle(R.string.app_name);
333            viewSwitch.showPrevious();
334        }
335 
336        itemPropertiesAdapter.notifyDataSetChanged();
337        listPropertiesAdapter.notifyDataSetChanged();
338    }
339    
340    @Override
341    protected void onStart()
342    {
343        Log.v(L.TAG, "SimplyDoActivity.onStart(): called");
344        
345        super.onStart();
346        
347        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
348        
349        String itemSort = prefs.getString("itemSorting", ItemListSorter.PREF_ACTIVE_STARRED);
350        //Log.v(L.TAG, "itemSort = " + itemSort);
351        
352        itemListSorter.setSortingMode(itemSort);
353        itemListSorter.sort(dataViewer.getItemData());
354        itemPropertiesAdapter.notifyDataSetChanged();
355        
356        String listSort = prefs.getString("listSorting", ListListSorter.PREF_ALPHA);
357        listListSorter.setSortingMode(listSort);
358        //Log.v(L.TAG, "listSort = " + listSort);
359        
360        listListSorter.sort(dataViewer.getListData());
361        listPropertiesAdapter.notifyDataSetChanged();
362    }
363 
364 
365    @Override
366    protected void onSaveInstanceState(Bundle outState)
367    {
368        Log.v(L.TAG, "SimplyDoActivity.onSaveInstanceState() called");
369        
370        super.onSaveInstanceState(outState);
371        
372        ListDesc selectedList = dataViewer.getSelectedList();
373        if(selectedList != null)
374        {
375            outState.putSerializable("currentListId", (Integer)selectedList.getId());
376        }
377        else
378        {
379            outState.putSerializable("currentListId", null);
380        }
381    }
382 
383 
384    @Override
385    protected void onDestroy()
386    {
387        Log.v(L.TAG, "SimplyDoActivity.onDestroy() called");
388        
389        super.onDestroy();
390        
391        dataViewer.close();
392        
393        instance = null;
394    }
395 
396 
397    @Override
398    public void onBackPressed()
399    {
400        Log.v(L.TAG, "SimplyDoActivity.onBackPressed() called");
401        
402        ViewSwitcher viewSwitch = (ViewSwitcher)findViewById(R.id.ListsItemsSwitcher);
403        int displayed = viewSwitch.getDisplayedChild();
404        
405        if(displayed == 0)
406        {
407            super.onBackPressed();
408        }
409        else
410        {
411            setTitle(R.string.app_name);
412            viewSwitch.showPrevious();
413            dataViewer.setSelectedList(null);
414            itemPropertiesAdapter.notifyDataSetChanged();
415        }
416    }
417 
418 
419    @Override
420    public boolean onCreateOptionsMenu(Menu menu)
421    {
422        Log.v(L.TAG, "SimplyDoActivity.onCreateOptionsMenu() called");
423        return super.onCreateOptionsMenu(menu);
424    }
425 
426 
427    @Override
428    public boolean onPrepareOptionsMenu(Menu menu)
429    {
430        Log.v(L.TAG, "SimplyDoActivity.onPrepareOptionsMenu() called");
431        
432        menu.clear();
433        ViewSwitcher viewSwitch = (ViewSwitcher)findViewById(R.id.ListsItemsSwitcher);
434        boolean isItemDisplay = viewSwitch.getDisplayedChild() != 0;
435        
436        if(isItemDisplay)
437        {
438            MenuItem deleteInactiveMI = menu.add(Menu.NONE, DELETE_INACTIVE, Menu.NONE, R.string.optionsMenuDeleteInactive);
439            deleteInactiveMI.setIcon(android.R.drawable.ic_menu_delete);
440        }
441        
442        MenuItem settingsMI = menu.add(Menu.NONE, SETTINGS, Menu.NONE, R.string.optionsMenuSettings);
443        settingsMI.setIcon(android.R.drawable.ic_menu_preferences);
444        
445        if(isItemDisplay)
446        {
447            MenuItem sortNowMI = menu.add(Menu.NONE, SORT_NOW, Menu.NONE, R.string.optionsMenuSort);
448            sortNowMI.setIcon(android.R.drawable.ic_menu_sort_by_size);
449        }
450        
451        return true;
452    }
453    
454    
455 
456    @Override
457    public boolean onMenuItemSelected(int featureId, MenuItem item)
458    {
459        Log.v(L.TAG, "SimplyDoActivity.onMenuItemSelected() called");
460        
461        switch(item.getItemId())
462        {
463        case DELETE_INACTIVE:
464        {
465            ListDesc currentList = dataViewer.getSelectedList();
466            if(currentList == null)
467            {
468                Log.e(L.TAG, "Delete inactive called but selected list was null");
469                return true;
470            }
471            Log.d(L.TAG, "Deleting Inactive");
472            
473            deleteInactiveAction.deleteInactive(DIALOG_DELETE_INACTIVE);
474            
475            return true;
476        }
477        case SETTINGS:
478        {
479            Intent settingsActivity = new Intent(getBaseContext(), SettingsActivity.class);
480            startActivity(settingsActivity);
481            return true;
482        }
483        case SORT_NOW:
484        {
485            itemListSorter.sort(dataViewer.getItemData());
486            itemPropertiesAdapter.notifyDataSetChanged();
487            return true;
488        }
489        case DELETE_LIST:
490            Log.d(L.TAG, "Got Delete List");
491            // Call are you sure?
492            showDialog(DIALOG_LIST_DELETE);
493            return true;
494        case DELETE_ITEM:
495            Log.d(L.TAG, "Got Delete Item");
496            if(ctxItem.isActive())
497            {
498                // Call are you sure?
499                showDialog(DIALOG_ITEM_DELETE);
500            }
501            else
502            {
503                contextDeleteItem();
504            }
505            return true;
506        case EDIT_ITEM:
507            Log.d(L.TAG, "Got Edit Item");
508            showDialog(DIALOG_ITEM_EDIT);
509            return true;
510        case EDIT_LIST:
511            Log.d(L.TAG, "Got Edit List");
512            showDialog(DIALOG_LIST_EDIT);
513            return true;
514        case TOGGLE_STAR:
515            if(ctxItem == null)
516            {
517                Log.e(L.TAG, "Toggle star but no context item!");
518                return true;
519            }
520            Log.d(L.TAG, "Toggling star");
521            
522            dataViewer.updateItemStarness(ctxItem, !ctxItem.isStar());
523            itemListSorter.markStarredUpdate(ctxItem);
524            itemPropertiesAdapter.notifyDataSetChanged();
525            return true;
526        case MOVE_ITEM:
527            if(ctxItem == null)
528            {
529                Log.e(L.TAG, "Move item selected but no context item!");
530                return true;
531            }
532            Log.d(L.TAG, "Displaying move item dialog");
533            
534            showDialog(DIALOG_ITEM_MOVE);
535            
536            return true;
537        }
538        
539        return super.onMenuItemSelected(featureId, item);
540    }
541 
542 
543    @Override
544    protected Dialog onCreateDialog(int id)
545    {
546        Log.v(L.TAG, "SimplyDoActivity.onCreateDialog(): Entered");
547        
548        Dialog dialog = null;
549                
550        switch(id)
551        {
552            case DIALOG_LIST_DELETE:
553            {
554                dialog = listDeleteBuilder.create();
555                break;
556            }
557            case DIALOG_ITEM_DELETE:
558            {
559                dialog = itemDeleteBuilder.create();
560                break;
561            }
562            case DIALOG_ITEM_EDIT:
563            {
564                itemEditDialog = itemEditBuilder.create();
565                itemEditDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
566                dialog = itemEditDialog;
567                break;
568            }
569            case DIALOG_LIST_EDIT:
570            {
571                listEditDialog = listEditBuilder.create();
572                listEditDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
573                dialog = listEditDialog;
574                break;
575            }
576            case DIALOG_ITEM_MOVE:
577            {
578                dialog = moveItemToAction.createDialog();
579                break;
580            }
581            case DIALOG_DELETE_INACTIVE:
582            {
583                dialog = deleteInactiveAction.createDialog();
584                break;
585            }
586        }
587        
588        if(dialog == null)
589        {
590            dialog = super.onCreateDialog(id);
591        }
592        
593        Log.v(L.TAG, "SimplyDoActivity.onCreateDialog(): Exit");
594        return dialog;
595    }
596    
597    
598    @Override
599        public void onPrepareDialog(int id, Dialog dialog)
600    {
601        Log.v(L.TAG, "SimplyDoActivity.onPrepareDialog(): Entered");
602        
603        switch(id)
604        {
605        case DIALOG_ITEM_EDIT:
606            if(ctxItem != null)
607            {
608                itemEditView.setText(ctxItem.getLabel());
609            }
610            else
611            {
612                Log.e(L.TAG, "onPrepareDialog()/DIALOG_ITEM_EDIT called for nonexistant item");
613            }
614            break;
615        case DIALOG_LIST_EDIT:
616            if(ctxList != null)
617            {
618                listEditView.setText(ctxList.getLabel());            
619            }
620            else
621            {
622                Log.e(L.TAG, "onPrepareDialog()/DIALOG_LIST_EDIT called for nonexistant list");
623            }
624            break;
625        case DIALOG_ITEM_MOVE:
626            if(ctxItem != null)
627            {
628                moveItemToAction.prepareDialog(dialog, ctxItem);
629            }
630            else
631            {
632                Log.e(L.TAG, "onPrepareDialog()/DIALOG_ITEM_MOVE called for nonexistant item");
633            }
634            break;
635        default:
636            super.onPrepareDialog(id, dialog);
637            break;
638        }
639 
640        Log.v(L.TAG, "SimplyDoActivity.onPrepareDialog(): Exit");
641    }
642    
643    
644    private void listSelected(ListDesc list, boolean animate)
645    {
646        //Log.v(L.TAG, "SimplyDoActivity.listSelected() called on list " + list.getId());
647        
648        setTitle(list.getLabel());
649        
650        dataViewer.setSelectedList(list);
651        itemListSorter.sort(dataViewer.getItemData());
652        itemPropertiesAdapter.notifyDataSetChanged();
653        
654        ViewSwitcher viewSwitch = (ViewSwitcher)findViewById(R.id.ListsItemsSwitcher);
655        
656        if(animate)
657        {
658            viewSwitch.showNext();
659        }
660        else
661        {
662            viewSwitch.reset();
663            viewSwitch.setAnimateFirstView(false);
664            viewSwitch.setDisplayedChild(1);
665        }
666    }
667    
668    
669    private void itemSelected(ItemDesc item)
670    {
671        Log.v(L.TAG, "Item selected " + item.getLabel());
672        
673        dataViewer.updateItemActiveness(item, !item.isActive());
674        itemListSorter.markActivityUpdate(item);
675        itemPropertiesAdapter.notifyDataSetChanged();
676        listPropertiesAdapter.notifyDataSetChanged();
677    }
678    
679    
680    private void addList()
681    {
682        EditText editText = (EditText)findViewById(R.id.AddListEditText);
683        
684        String txt = editText.getText().toString();
685        String txtTrim = txt.trim();
686        
687        if(txtTrim.length() > 0)
688        {
689            dataViewer.createList(txtTrim);
690            listListSorter.sort(dataViewer.getListData());
691            listPropertiesAdapter.notifyDataSetChanged();
692            editText.getText().clear();
693        }
694    }
695    
696    
697    private void addItem()
698    {
699        EditText editText = (EditText)findViewById(R.id.AddItemEditText);
700        
701        String txt = editText.getText().toString();
702        String txtTrim = txt.trim();
703        
704        if(txtTrim.length() > 0)
705        {
706            ListDesc currentList = dataViewer.getSelectedList();
707            if(currentList != null)
708            {
709                dataViewer.createItem(txtTrim);
710                itemPropertiesAdapter.notifyDataSetChanged();
711                listPropertiesAdapter.notifyDataSetChanged();
712                editText.getText().clear();
713            }
714            else
715            {
716                Log.e(L.TAG, "Add item called but selected list was null");
717            }
718        }
719    }
720    
721    
722    private void itemEditOk()
723    {
724        String txt = itemEditView.getText().toString();
725        
726        if(txt.trim().length() > 0)
727        {
728            dataViewer.updateItemLabel(ctxItem, txt);
729            itemListSorter.markEditUpdate(ctxItem);
730            itemPropertiesAdapter.notifyDataSetChanged();
731        }
732    }
733    
734    
735    private void listEditOk()
736    {
737        String txt = listEditView.getText().toString();
738        
739        if(txt.trim().length() > 0)
740        {
741            dataViewer.updateListLabel(ctxList.getId(), txt);
742            listPropertiesAdapter.notifyDataSetChanged();
743        }
744    }
745    
746    
747    private void contextDeleteList()
748    {
749        Log.d(L.TAG, "Deleting list " + ctxList.getLabel());
750        
751        dataViewer.deleteList(ctxList.getId());
752        listPropertiesAdapter.notifyDataSetChanged();
753        
754        ctxList = null;
755    }
756    
757    private void contextDeleteItem()
758    {
759        Log.d(L.TAG, "Deleting item " + ctxItem.getLabel());
760        
761        dataViewer.deleteItem(ctxItem);
762        itemPropertiesAdapter.notifyDataSetChanged();
763        listPropertiesAdapter.notifyDataSetChanged();
764        
765        ctxItem = null;
766    }
767    
768    
769    private class ItemsListReactor implements OnItemClickListener, View.OnCreateContextMenuListener
770    {
771        @Override
772        public void onCreateContextMenu(ContextMenu menu, View v,
773                ContextMenuInfo menuInfo)
774        {
775            Log.v(L.TAG, "ItemsListReactor.onCreateContextMenu()");
776            
777            AdapterContextMenuInfo ctxMenuInfo = (AdapterContextMenuInfo)menuInfo;
778            ListView listView = (ListView)findViewById(R.id.ItemsListView);
779            ctxItem = (ItemDesc)listView.getItemAtPosition(ctxMenuInfo.position);
780 
781            menu.setHeaderTitle(R.string.itemOptionsTitle);
782            menu.add(Menu.NONE, EDIT_ITEM, Menu.NONE, R.string.itemOptionsEdit);
783            menu.add(Menu.NONE, DELETE_ITEM, Menu.NONE, R.string.itemOptionsDelete);
784            int toggleText;
785            if(ctxItem.isStar())
786            {
787                toggleText = R.string.itemOptionsRemoveStar;
788            }
789            else
790            {
791                toggleText = R.string.itemOptionsAddStar;
792            }
793            menu.add(Menu.NONE, TOGGLE_STAR, Menu.NONE, toggleText);
794            if(dataViewer.getListData().size() > 1)
795            {
796                menu.add(Menu.NONE, MOVE_ITEM, Menu.NONE, R.string.itemOptionsMoveTo);
797            }
798        }
799 
800        
801        @Override
802        public void onItemClick(AdapterView<?> adapter, View view, int position,
803                long id)
804        {
805            Log.v(L.TAG, "ItemsListReactor.onItemClick()");
806            
807            ListView listView = (ListView)findViewById(R.id.ItemsListView);
808            ItemDesc itemDesc = (ItemDesc)listView.getItemAtPosition(position);
809            itemSelected(itemDesc);
810        }
811        
812    }
813    
814    private class ListsListReactor implements OnItemClickListener, View.OnCreateContextMenuListener
815    {
816        @Override
817        public void onItemClick(AdapterView<?> adapter, View view, int position,
818                long id)
819        {
820            Log.v(L.TAG, "ListsListReactor.onItemClick()");
821            
822            ListView listView = (ListView)findViewById(R.id.ListsListView);
823            ListDesc listDesc = (ListDesc)listView.getItemAtPosition(position);
824            listSelected(listDesc, true);
825        }
826 
827        @Override
828        public void onCreateContextMenu(ContextMenu menu, View v,
829                ContextMenuInfo menuInfo)
830        {
831            Log.v(L.TAG, "ListsListReactor.onCreateContextMenu()");
832            
833            AdapterContextMenuInfo ctxMenuInfo = (AdapterContextMenuInfo)menuInfo;
834            ListView listView = (ListView)findViewById(R.id.ListsListView);
835            ctxList = (ListDesc)listView.getItemAtPosition(ctxMenuInfo.position);
836 
837            menu.setHeaderTitle(R.string.listOptionsTitle);
838            menu.add(Menu.NONE, EDIT_LIST, Menu.NONE, R.string.listOptionsEdit);
839            menu.add(Menu.NONE, DELETE_LIST, Menu.NONE, R.string.listOptionsDelete);
840        }
841    
842    }
843}

[all classes][kdk.android.simplydo]
EMMA 2.0.5312 (C) Vladimir Roubtsov